function loadCSS(url) {
	const link = document.createElement('link');
	link.rel = 'stylesheet';
	link.type = 'text/css';
	link.href = url;
	document.head.appendChild(link);
}

/* 根据当前时间计算对应季节 */
function getSeason() {
	let month = (new Date()).getMonth() + 1;
	const seasons = {
		'spring': [3, 4, 5, ],
		'summer': [6, 7, 8],
		'autumn': [9, 10, 11],
		'winter': [12, 1, 2]
	}
	let season = Object.keys(seasons).find(key => seasons[key].includes(month)); //获取当前季节
	return season;
}

function formatDate(date, format) {
	const map = {
		'YYYY': date.getFullYear(),
		'YY': String(date.getFullYear()).slice(-2),
		'MMMM': date.toLocaleString('en', {
			month: 'long'
		}),
		'MMM': date.toLocaleString('en', {
			month: 'short'
		}),
		'MM': String(date.getMonth() + 1).padStart(2, '0'),
		'M': String(date.getMonth() + 1),
		'DD': String(date.getDate()).padStart(2, '0'),
		'D': String(date.getDate()),
		'dddd': date.toLocaleString('en', {
			weekday: 'long'
		}),
		'ddd': date.toLocaleString('en', {
			weekday: 'short'
		}),
		'Do': date.getDate() + ['th', 'st', 'nd', 'rd'][((date.getDate() % 10) > 3 || [11, 12, 13].includes(date.getDate())) ? 0 : date.getDate() % 10],
		'hh': String(date.getHours()).padStart(2, '0'),
		'h': String(date.getHours()),
		'mm': String(date.getMinutes()).padStart(2, '0'),
		'm': String(date.getMinutes()),
		'ss': String(date.getSeconds()).padStart(2, '0'),
		's': String(date.getSeconds()),
		'A': date.getHours() < 12 ? 'AM' : 'PM'
	};
	return format.replace(/\b(?:YYYY|YY|MMMM|MMM|MM|M|DD|D|dddd|ddd|Do|hh|h|mm|m|ss|s|A)\b/g, match => map[match] || match);
}

export {
	loadCSS,
	getSeason,
	formatDate
};